package caidan.data;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import jinyilw.common.Alignment;
import jinyilw.swing.FontTools;
import jinyilw.swing.rlaf.utils.RBorderFactory;
import jinyilw.swing.visuals.layout.OneRowLayout;

public class CheckPanel extends JPanel
{
	private static final long serialVersionUID = 8273525266717892127L;

	private JCheckBox[] boxs;
	private boolean[] datas;

	public CheckPanel(String description, String[] contents)
	{
		super(new OneRowLayout(Alignment.LEFT));
		setBorder(RBorderFactory.getDefaultBorder());
		Font font = FontTools.getSystemFont(12);
		JLabel dLabel = new JLabel(description);
		dLabel.setFont(font);
		add(dLabel);
		boxs = new JCheckBox[contents.length];
		for (int i = 0; i < boxs.length; i++)
		{
			boxs[i] = new JCheckBox(contents[i]);
			boxs[i].setFont(font);
			add(boxs[i]);
			int ii = i;
			boxs[i].addActionListener(new ActionListener()
			{
				int j = ii;
				@Override
				public void actionPerformed(ActionEvent e)
				{
					datas[j] = boxs[j].isSelected();
				}
			});
			boxs[i].setFocusable(false);
		}
	}

	public void setDatas(boolean[] bs)
	{
		datas = bs;
		for (int i = 0; i < boxs.length; i++)
			boxs[i].setSelected(bs[i]);
	}
}
